﻿using OccurrencesCore.Model;
using OccurrencesCore.Model.Enum;
using OccurrencesWorkflow.BaseControl.Interface;
using OccurrencesWorkflow.SpecializedControl.ScheduledReturn;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OccurrencesWorkflow.BaseControl.Base
{
    public abstract class WorkflowControl : IWorkflowControl
    {
        internal static WorkflowControl GetWorkflow(Occurrence occurrence)
        {
            WorkflowControl workflow = null;
            switch ((OccurenceTypeEnum)occurrence.OccurrenceTypeId)
            {
                case OccurenceTypeEnum.ScheduledReturn:
                    {
                        workflow = new ScheduledReturnWorflowControl();
                        break;
                    }
            }
            if (workflow != null)
            {
                return workflow;
            }
            else
            {
                throw new Exception("The workflow for this type of occurrence is not yet configured");
            }
        }


        public static void CreateWorkflow(Occurrence occurrence)
        {
            WorkflowControl workflow = GetWorkflow(occurrence);        
            if (workflow != null)
            {
                workflow.Initialize(occurrence);               
            }          
        }

        public abstract void Initialize(Occurrence occurrence);

        public abstract void NotifyTaskChanged(WorkflowTask task);
    }
}
